package cn.com.bob.library.config;


import cn.com.bob.library.interceptor.LoginInterceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Bob
 * @Version：1.0
 * 自定义拦截器进行注册
 */
@Component
public class LoginInterceptorConfiguration implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //自定义拦截器对象
        HandlerInterceptor loginInterceptor = new LoginInterceptor();
        //添加白名单
        List<String> list = new ArrayList<>();
        list.add("/bootstrap3/**");
        list.add("/css/**");
        list.add("/images/**");
        list.add("/js/**");
        list.add("/");
        list.add("/register.html");
        list.add("/user/register");
        list.add("/user/login");


        //注册登录拦截器
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns(list);

    }
}
